Skip to content

Playwright: Extend coverage to kb helpfulness widget feedback canceled state & helpfulness metadata percentage information #6653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def __init__(self, page: Page):
self.navbar_option = lambda option_name: page.locator(
"ul[class='sidebar-nav--list'] li").get_by_role("link").filter(has_text=option_name)

# Product topic page article metadata locators.
self.article_helpfulness_count = lambda article_name: page.locator(
f"//a[normalize-space(text())='{article_name}']/../../div[@id='document_metadata']//"
f"span[@class='helpful-count']")

# Page content actions.
def get_all_listed_article_titles(self) -> list[str]:
"""Returns a list of all the article titles displayed on the page."""
Expand Down Expand Up @@ -52,3 +57,7 @@ def get_navbar_links_text(self) -> list[str]:
def get_navbar_option_link(self, option_name: str) -> str:
"""Returns the href value of a particular navbar option."""
return self._get_element_attribute_value(self.navbar_option(option_name),"href")

def is_article_helpfulness_metadata_displayed(self, article_title: str) -> bool:
"""Checks if the article helpfulness metadata is displayed."""
return self._is_element_visible(self.article_helpfulness_count(article_title))
3 changes: 2 additions & 1 deletion playwright_tests/pages/auth_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def __init__(self, page: Page):
self.user_logged_in_sign_in_button = page.get_by_role(
"button", name="Sign in", exact=True)
self.enter_your_email_input_field = page.locator("input[name='email']")
self.enter_your_email_submit_button = page.locator("button#submit-btn")
self.enter_your_email_submit_button = page.get_by_role(
"button", name='Sign up or sign in', exact=True)
self.enter_your_password_input_field = page.locator("input[type='password']")
self.enter_your_password_submit_button = page.get_by_role(
"button", name="Sign in", exact=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def __init__(self, page: Page):
"div[class='document--contributors-list text-body-xs']").get_by_role(
"link", name=f'{username}', exact=True)

# Article metadata locators.
self.kb_article_helpfulness_count = page.locator(
"div#document_metadata span[class='helpful-count']")

# Editing Tools options locators.
self.editing_tools_article_option = page.get_by_role("link", name="Article",
exact=True)
Expand Down Expand Up @@ -57,6 +61,9 @@ def click_on_a_particular_breadcrumb(self, breadcrumb_name: str):
def get_text_of_all_article_breadcrumbs(self) -> list[str]:
return self._get_text_of_elements(self.kb_article_breadcrumbs_list)

def get_text_of_kb_article_helpfulness_count_metadata(self) -> str:
return self._get_text_of_element(self.kb_article_helpfulness_count)

def get_text_of_article_title(self) -> str:
return self._get_text_of_element(self.kb_article_heading)

Expand Down
8 changes: 7 additions & 1 deletion playwright_tests/test_data/ga4_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
"survey_type": "unhelpful"
}
},
"cancel_survey": {
"cancel_survey_helpful": {
"event": "article_survey_closed",
"parameters": {
"survey_type": "helpful"
}
},
"cancel_survey_unhelpful": {
"event": "article_survey_closed",
"parameters": {
"survey_type": "unhelpful"
}
},
"article_helpfulness": {
"event": "article_vote",
"parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pytest_check import check
import pytest
import re
from playwright.sync_api import expect, Page
from playwright.sync_api import expect, Page, BrowserContext
from slugify import slugify

from playwright_tests.core.utilities import Utilities
Expand Down Expand Up @@ -1745,7 +1745,8 @@ def test_article_topic_and_product_change(page: Page):
sumo_pages.kb_article_deletion_flow.delete_kb_article()


# C2550394 C2877651 C2877652 C2877653 C2877654
# C2550394 C2877651 C2877652 C2877653 C2877654 C2843760 C2843762 C2844267 C2844282 C2844332
# C2844333
@pytest.mark.kbArticleCreationAndAccess
@pytest.mark.parametrize("vote_type", ["Article is accurate", "Article is easy to understand",
"The visuals are helpful",
Expand Down Expand Up @@ -1812,7 +1813,75 @@ def test_article_helpfulness_votes(page: Page, vote_type):
sumo_pages.kb_article_deletion_flow.delete_kb_article()


# C2877656 C2877657 C2877658 C2877659 C2877660
# C2877655 C2843760 C2843762 C2844267 C2844282 C2844332 C2844333
@pytest.mark.kbArticleCreationAndAccess
@pytest.mark.parametrize("vote_type", ["Article is accurate", "Article is easy to understand",
"The visuals are helpful",
"Article provided the information I needed", "Other"])
def test_article_helpfulness_cancel_vote(page: Page, vote_type):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
events = {}
ga_events = utilities.ga4_data

with allure.step("Sign in with an Admin account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

with allure.step("Create a new simple article"):
sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
page=page, approve_revision=True)
sumo_pages.kb_article_page.click_on_article_option()

with allure.step("Sign in with an normal account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))

with allure.step(f"Voting the article as {vote_type}"):
page.on("console", lambda msg: events.update(log) if (log := utilities.get_ga_logs(
msg)) is not None and msg.type == "log" else None)

sumo_pages.kb_article_page.click_on_helpful_button()
with check, allure.step("Verifying that the correct event is sent"):
check.is_true(events.items() <= ga_events['article_helpfulness'].items())

sumo_pages.kb_article_page.click_on_helpfulness_option(vote_type)
with check, allure.step("Verifying that the correct survey open event is sent"):
check.is_true(events.items() <= ga_events['open_survey_helpful'].items())

sumo_pages.kb_article_page.fill_helpfulness_textarea_field("Playwright vote test")

sumo_pages.kb_article_page.click_on_helpfulness_cancel_button()
with check, allure.step("Verifying that the correct cancel survey event is sent"):
check.is_true(events.items() <= ga_events['cancel_survey_helpful'].items())

with check, allure.step("Verifying that the correct widget is displayed"):
check.equal(
sumo_pages.kb_article_page.get_survey_message_text(),
KBArticlePageMessages.KB_SURVEY_FEEDBACK_NO_ADDITIONAL_DETAILS
)

with check, allure.step("Waiting for 6 seconds and verifying that the widget is no longer"
" displayed"):
utilities.wait_for_given_timeout(6000)
check.is_false(sumo_pages.kb_article_page.is_helpfulness_widget_displayed())

with check, allure.step("Refreshing the page and verifying that the widget is no longer "
"displayed"):
page.reload()
check.is_false(sumo_pages.kb_article_page.is_helpfulness_widget_displayed())

with allure.step("Deleting the kb article"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
sumo_pages.kb_article_deletion_flow.delete_kb_article()


# C2877656 C2877657 C2877658 C2877659 C2877660 C2844337 C2844339 C2844341 C2844342 C2844343
# C2844345
@pytest.mark.kbArticleCreationAndAccess
@pytest.mark.parametrize("vote_type", ["Article is inaccurate", "Article is confusing",
"Missing, unclear, or unhelpful visuals",
Expand Down Expand Up @@ -1880,3 +1949,177 @@ def test_article_unhelpfulness_votes(page: Page, vote_type):
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
sumo_pages.kb_article_deletion_flow.delete_kb_article()


# C2877661 C2844337 C2844339 C2844341 C2844342 C2844343 C2844345
@pytest.mark.kbArticleCreationAndAccess
@pytest.mark.parametrize("vote_type", ["Article is inaccurate", "Article is confusing",
"Missing, unclear, or unhelpful visuals",
"Article didn't provide the information I needed",
"Other"])
def test_article_unhelpfulness_cancel_vote(page: Page, vote_type):
utilities = Utilities(page)
sumo_pages = SumoPages(page)
events = {}
ga_events = utilities.ga4_data

with allure.step("Sign in with an Admin account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

with allure.step("Create a new simple article"):
sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
page=page, approve_revision=True)
sumo_pages.kb_article_page.click_on_article_option()

with allure.step("Sign in with an normal account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))

with allure.step(f"Voting the article as {vote_type}"):
page.on("console", lambda msg: events.update(log) if (log := utilities.get_ga_logs(
msg)) is not None and msg.type == "log" else None)

sumo_pages.kb_article_page.click_on_unhelpful_button()
with check, allure.step("Verifying that the correct event is sent"):
check.is_true(events.items() <= ga_events['article_unhelpfulness'].items())

sumo_pages.kb_article_page.click_on_helpfulness_option(vote_type)
with check, allure.step("Verifying that the correct survey open event is sent"):
check.is_true(events.items() <= ga_events['open_survey_unhelpful'].items())

sumo_pages.kb_article_page.fill_helpfulness_textarea_field("Playwright vote test")

sumo_pages.kb_article_page.click_on_helpfulness_cancel_button()
with check, allure.step("Verifying that the correct survey submitted event is sent"):
check.is_true(events.items() <= ga_events['cancel_survey_unhelpful'].items())

with check, allure.step("Verifying that the correct widget is displayed"):
check.equal(
sumo_pages.kb_article_page.get_survey_message_text(),
KBArticlePageMessages.KB_SURVEY_FEEDBACK_NO_ADDITIONAL_DETAILS
)

with check, allure.step("Waiting for 6 seconds and verifying that the widget is no longer"
" displayed"):
utilities.wait_for_given_timeout(6000)
check.is_false(sumo_pages.kb_article_page.is_helpfulness_widget_displayed())

with check, allure.step("Refreshing the page and verifying that the widget is no longer "
"displayed"):
page.reload()
check.is_false(sumo_pages.kb_article_page.is_helpfulness_widget_displayed())

with allure.step("Deleting the kb article"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
sumo_pages.kb_article_deletion_flow.delete_kb_article()


# C2616585
@pytest.mark.kbArticleCreationAndAccess
def test_article_helpfulness_metadata_count(page: Page):
utilities = Utilities(page)
sumo_pages = SumoPages(page)

with allure.step("Sign in with an Admin account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

with allure.step("Create a new simple article"):
article_info = sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
page=page,topic=374, approve_revision=True)
sumo_pages.kb_article_page.click_on_article_option()

with allure.step("Voting the article as helpful"):
sumo_pages.kb_article_page.click_on_helpful_button()
sumo_pages.kb_article_page.click_on_helpfulness_option("Article is accurate")
sumo_pages.kb_article_page.fill_helpfulness_textarea_field("Playwright vote test")
sumo_pages.kb_article_page.click_on_helpfulness_submit_button()
utilities.refresh_page()

with check, allure.step("Verifying that the correct kb article metadata information is "
"displayed"):
check.equal(
sumo_pages.kb_article_page.get_text_of_kb_article_helpfulness_count_metadata(),
"100%"
)

with allure.step("Signing in with a different user"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))

with allure.step("Voting the article as unhelpful"):
sumo_pages.kb_article_page.click_on_unhelpful_button()
sumo_pages.kb_article_page.click_on_helpfulness_option("Article is inaccurate")
sumo_pages.kb_article_page.fill_helpfulness_textarea_field("Playwright vote test")
sumo_pages.kb_article_page.click_on_helpfulness_submit_button()
utilities.refresh_page()

with check, allure.step("Verifying that the correct kb article metadata information is "
"displayed"):
check.equal(
sumo_pages.kb_article_page.get_text_of_kb_article_helpfulness_count_metadata(),
"50%"
)

with check, allure.step("Navigating to the topics page associated with this article and "
"verifying that the helpfulness percentage metadata information is "
"not displayed"):
utilities.navigate_to_link(utilities.general_test_data["product_topics"]["Firefox"])
check.is_false(
sumo_pages.product_topics_page.is_article_helpfulness_metadata_displayed(
article_info["article_title"])
)

with allure.step("Deleting the kb article"):
sumo_pages.product_topics_page.click_on_a_particular_article(article_info["article_title"])
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
sumo_pages.kb_article_deletion_flow.delete_kb_article()


# C2895037
@pytest.mark.kbArticleCreationAndAccess
def test_voting_the_same_article_twice_is_not_possible(page: Page, context: BrowserContext):
utilities = Utilities(page)
sumo_pages = SumoPages(page)

with allure.step("Sign in with an Admin account"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

with allure.step("Create a new simple article"):
article_info = sumo_pages.submit_kb_article_flow.kb_article_creation_via_api(
page=page, topic=374, approve_revision=True)
sumo_pages.kb_article_page.click_on_article_option()

with allure.step("Sign in with a different user"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_12"]
))

with allure.step("Opening a new browser window, navigating to the newly created kb article "
"and voting the article as helpful"):
new_page = context.new_page()
new_page.goto(article_info["article_url"])
sumo_pages2 = SumoPages(new_page)
sumo_pages2.kb_article_page.click_on_helpful_button()

with check, allure.step("Verifying that the helpfulness widget is no longer displayed inside"
" first browser window"):
utilities.wait_for_given_timeout(1000)
check.is_false(sumo_pages.kb_article_page.is_helpfulness_widget_displayed())

with allure.step("Deleting the kb article"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
sumo_pages.kb_article_deletion_flow.delete_kb_article()